<%--
  Created by IntelliJ IDEA.
  User: chen
  Date: 17-9-17
  Time: 下午12:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>

<link rel="stylesheet" href="${basePath}/static/css/bootstrap.min.css">
<link rel="stylesheet" href="${basePath}/static/css/all.css" >

<script src="${basePath}/static/js/jquery-3.2.1.min.js"></script>
<script src="${basePath}/static/js/bootstrap.min.js"></script>
<script src="${basePath}/static/js/function.js" type="text/javascript"></script>
<div class="iframe_div">
    <table id="table_leaseData" class="table table-striped table-bordered table-hover  table-condensed iframe-table">
        <tr>
            <td>书本</td>
            <td>书名</td>
            <td>借阅时间</td>
            <td>归还</td>
        </tr>
        <c:forEach var="lease" items="${leaseList}" step="1">
            <c:set var="book" value="${lease.getBook()}"/>
            <tr id="tr_${book.getBook_id()}">
                <td class="book_id">${book.getBook_id()}</td>
                <td>${book.getBook_name()}</td>
                <td>${lease.getLease_time()}</td>
                <td><a class="a_return" href="#">归还</a></td>

            </tr>
        </c:forEach>
        <script type="text/javascript">
            var btn_return = $("a.a_return");

            btn_return.click(function () {
                var bookId = $(this).parents().siblings(".book_id").text();
                var URL = bookId+"/returnBook";
                $.ajax({
                    url:URL,
                    type:"POST",
                    dataType:"json",
                    data:{
                        book_id:bookId,
                        student_id:${sessionScope.get("loginUser").getStudent().getStudent_id()}
                    },
                    success:function (data) {
                        if(data.symbol){
                            alert("归还成功")
                            $("tr#tr_"+bookId).remove();
                        }else{
                            alert("归还失败")
                        }
                    },
                    error:function () {
                        alert("通信失败")
                    }
                });
            });
        </script>

    </table>
</div>
